﻿using System.Collections.Generic;
using System.Collections;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
using System;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using System.Xml.Schema;

namespace ScormModel
{
    [Serializable()]
    public class SequencingRules
    {
        [NonSerialized]
        private XmlNode _sequencingRulesContent;
        private List<ExitConditionRule> _listExitConditionRule;
        private List<PostConditionRule> _listPostConditionRule;
        private List<PreConditionRule> _listPreConditionRule;
        [XmlElement("exitConditionRule", Namespace = "http://www.imsglobal.org/xsd/imsss")]
        public List<ExitConditionRule> ListExitConditionRule
        {
            get { return this._listExitConditionRule; }
            set { this._listExitConditionRule = value; }
        }
        [XmlElement("postConditionRule", Namespace = "http://www.imsglobal.org/xsd/imsss")]
        public List<PostConditionRule> ListPostConditionRule
        {
            get { return this._listPostConditionRule; }
            set { this._listPostConditionRule = value; }
        }
        [XmlElement("preConditionRule", Namespace = "http://www.imsglobal.org/xsd/imsss")]
        public List<PreConditionRule> ListPreConditionRule
        {
            get { return this._listPreConditionRule; }
            set { this._listPreConditionRule = value; }
        }
       
        [XmlIgnoreAttribute]
        public XmlNode SequencingRulesContent
        {
            get { return this._sequencingRulesContent; }
            set { this._sequencingRulesContent = value; }
        }
        public void buildSequencingRules()
        {
            _listExitConditionRule = new List<ExitConditionRule>();
            _listPostConditionRule = new List<PostConditionRule>();
            _listPreConditionRule = new List<PreConditionRule>();
            for (int i = 0; i < _sequencingRulesContent.ChildNodes.Count; i++)
            {
                if (((XmlNode)(_sequencingRulesContent.ChildNodes[i])).Name == "imsss:preConditionRule")
                {
                    PreConditionRule preConditionRule = new PreConditionRule();
                    preConditionRule.PreConditionRuleContent = _sequencingRulesContent.ChildNodes[i];
                    preConditionRule.buildPreConditionRule();
                    _listPreConditionRule.Add(preConditionRule);
                }
                if (((XmlNode)(_sequencingRulesContent.ChildNodes[i])).Name == "imsss:exitConditionRule")
                {
                    ExitConditionRule exitConditionRule = new ExitConditionRule();
                    exitConditionRule.ExitConditionRuleContent = _sequencingRulesContent.ChildNodes[i];
                    exitConditionRule.buildExitConditionRule();
                    _listExitConditionRule.Add(exitConditionRule);
                }
                if (((XmlNode)(_sequencingRulesContent.ChildNodes[i])).Name == "imsss:postConditionRule")
                {
                    PostConditionRule postConditionRule = new PostConditionRule();
                    postConditionRule.PostConditionRuleContent = _sequencingRulesContent.ChildNodes[i];
                    postConditionRule.buildPostConditionRule();
                    _listPostConditionRule.Add(postConditionRule);
                }
            }
        }
    }
}
